﻿using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace syc.Sale
{
    public partial class 合同计划及完成情况 : System.Web.UI.Page
    {
        protected int m1 = 1;
        protected int m2 = 2;
        protected int m3 = 3;
        protected string 年度;
        protected string 季度;

        protected DateTime d1, d2, d3, d4;//d1月初日期，d2上旬截止日期,d3中旬截止日期,d4月末日期
        protected string 当前旬;
        protected decimal 套管合计到货量 = 0;
        protected decimal 油管合计到货量 = 0;
        protected decimal 套管欠交=0;
        protected decimal 油管欠交=0;
        protected decimal 套管提前交货量 = 0;
        protected decimal 油管提前交货量 = 0;
        protected decimal 套管未完成合同量 = 0;
        protected decimal 油管未完成合同量 = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                RiQi.Text = DateTime.Today.ToString("yyyy年M月d日");

                this.Year.SelectedValue = DateTime.Today.Year.ToString();
                this.Month.SelectedValue = DateTime.Today.Month.ToString();
                
               
            }
            年度 = this.Year.SelectedValue;
            string month = this.Month.SelectedValue;
            当前旬 = GetXun(this.Year.SelectedValue, this.Month.SelectedValue, DateTime.Parse(RiQi.Text));

            if (month == "1" || month == "2" || month == "3")
            {
                季度 = "1";
            }
            if (month == "4" || month == "5" || month == "6")
            {
                季度 = "2";
            }
            if (month == "7" || month == "8" || month == "9")
            {
                季度 = "3";
            }
            if (month == "10" || month == "11" || month == "12")
            {
                季度 = "4";
            }
            
            int jidu = int.Parse(季度);
            if (jidu == 1)
            {
                m1 = 1;
                m2 = 2;
                m3 = 3;
            }
            if (jidu == 2)
            {
                m1 = 4;
                m2 = 5;
                m3 = 6;
            }
            else if (jidu == 3)
            {
                m1 = 7;
                m2 = 8;
                m3 = 9;
            }
            else if (jidu == 4)
            {
                m1 = 10;
                m2 = 11;
                m3 = 12;
            }
        }
        public string GetXun(string yy, string mm,DateTime riqi)
        {
            string 当前旬="";
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            DataSet ds = new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter("select 月初日期,上旬日期,中旬日期,月末日期 from 供应处生产月设置 where 年度='" + yy + "' and 月份='" + mm + "'", Conn);
            sda.Fill(ds);
            try
            {
                d1 = DateTime.Parse(ds.Tables[0].Rows[0][0].ToString());
                d2 = DateTime.Parse(ds.Tables[0].Rows[0][1].ToString());
                d3 = DateTime.Parse(ds.Tables[0].Rows[0][2].ToString());
                d4 = DateTime.Parse(ds.Tables[0].Rows[0][3].ToString());
                if (riqi >= d1 && riqi <= d2)
                {
                    当前旬 = mm + "月上旬";
                }
                if(riqi>d2 && riqi<=d3){
                    当前旬 = mm + "月中旬";
                }
                if (riqi > d3 && riqi <= d4)
                {
                    当前旬 = mm + "月下旬";
                }
                this.Message.Text = ".查看成功";
                
            }
            catch
            {
                this.Message.Text = ".供应处该扎帐月没有设置";
            }
            return 当前旬;
        }
        protected void ToExcel_Click(object sender, EventArgs e)
        {
            string part1 = @"<html xmlns:o='urn:schemas-microsoft-com:office:office'
xmlns:x='urn:schemas-microsoft-com:office:excel'
xmlns='http://www.w3.org/TR/REC-html40'>
<meta http-equiv=Content-Type content='text/html; charset=utf-8'>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>Chinese User</o:Author>
  <o:LastAuthor>Chinese User</o:LastAuthor>
  <o:LastPrinted>2010-07-05T02:26:53Z</o:LastPrinted>
  <o:Created>2010-07-05T02:24:58Z</o:Created>
  <o:LastSaved>2010-07-05T02:27:02Z</o:LastSaved>
  <o:Company>Chinese ORG</o:Company>
  <o:Version>11.9999</o:Version>
 </o:DocumentProperties>
</xml><![endif]-->
<style>
<!--table
	{mso-displayed-decimal-separator:'\.';
	mso-displayed-thousand-separator:'\,';}
@page
	{margin:.48in .75in 1.0in .75in;
	mso-header-margin:.5in;
	mso-footer-margin:.5in;
	mso-page-orientation:landscape;}
tr
	{mso-height-source:auto;
	mso-ruby-visibility:none;}
col
	{mso-width-source:auto;
	mso-ruby-visibility:none;}
br
	{mso-data-placement:same-cell;}
.style0
	{mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	white-space:nowrap;
	mso-rotate:0;
	mso-background-source:auto;
	mso-pattern:auto;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	border:none;
	mso-protection:locked visible;
	mso-style-name:常规;
	mso-style-id:0;}
td
	{mso-style-parent:style0;
	padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	border:none;
	mso-background-source:auto;
	mso-pattern:auto;
	mso-protection:locked visible;
	white-space:nowrap;
	mso-rotate:0;}
.xl24
	{mso-style-parent:style0;
	font-weight:700;
	text-align:center;
	border-top:none;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl25
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:none;
	border-left:.5pt solid windowtext;}
.xl26
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:none;
	border-left:.5pt solid windowtext;
	white-space:normal;}
.xl27
	{mso-style-parent:style0;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl28
	{mso-style-parent:style0;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl29
	{mso-style-parent:style0;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl30
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl31
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;
	white-space:normal;}
.xl32
	{mso-style-parent:style0;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl33
	{mso-style-parent:style0;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl34
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl35
	{mso-style-parent:style0;
	font-weight:700;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl36
	{mso-style-parent:style0;
	text-align:center;
	border:.5pt solid windowtext;}
.xl37
	{mso-style-parent:style0;
	text-align:right;}
ruby
	{ruby-align:left;}
rt
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-char-type:none;
	display:none;}
-->
</style>
<!--[if gte mso 9]><xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>Sheet1</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:Print>
      <x:ValidPrinterInfo/>
      <x:PaperSizeIndex>9</x:PaperSizeIndex>
      <x:HorizontalResolution>600</x:HorizontalResolution>
      <x:VerticalResolution>600</x:VerticalResolution>
     </x:Print>
     <x:Selected/>
     <x:Panes>
      <x:Pane>
       <x:Number>3</x:Number>
       <x:ActiveRow>18</x:ActiveRow>
       <x:ActiveCol>9</x:ActiveCol>
      </x:Pane>
     </x:Panes>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet2</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet3</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
  <x:WindowHeight>9000</x:WindowHeight>
  <x:WindowWidth>11700</x:WindowWidth>
  <x:WindowTopX>240</x:WindowTopX>
  <x:WindowTopY>30</x:WindowTopY>
  <x:ProtectStructure>False</x:ProtectStructure>
  <x:ProtectWindows>False</x:ProtectWindows>
 </x:ExcelWorkbook>
</xml><![endif]-->
</head>

<body link=blue vlink=purple>

<table x:str border=0 cellpadding=0 cellspacing=0 width=951 style='border-collapse:
 collapse;table-layout:fixed;width:713pt'>
 <col width=72 style='mso-width-source:userset;mso-width-alt:2304;width:54pt'>
 <col width=87 style='mso-width-source:userset;mso-width-alt:2784;width:65pt'>
 <col width=72 span=11 style='width:54pt'>
 <tr height=34 style='mso-height-source:userset;height:25.5pt'>
  <td colspan=13 height=34 class=xl24 width=951 style='height:25.5pt;
  width:713pt'>@年度年@季度季度套管中标合同计划及完成情况</td>
 </tr>
 <tr height=19 style='height:14.25pt'>
  <td rowspan=2 height=38 class=xl25 style='border-bottom:.5pt solid black;
  height:28.5pt;border-top:none'>序号</td>
  <td rowspan=2 class=xl25 style='border-bottom:.5pt solid black;border-top:
  none'>中标单位</td>
  <td rowspan=2 class=xl25 style='border-bottom:.5pt solid black;border-top:
  none'>数量(吨)</td>
  <td rowspan=2 class=xl26 width=72 style='border-bottom:.5pt solid black;
  border-top:none;width:54pt'>单价<br>
    (元/吨)</td>
  <td colspan=9 class=xl27 style='border-right:.5pt solid black;border-left:
  none'>交货时间</td>
 </tr>
 <tr height=19 style='height:14.25pt'>
  <td height=19 class=xl32 style='height:14.25pt'>@m1月上旬</td>
  <td class=xl32>@m1月中旬</td>
  <td class=xl32>@m1月下旬</td>
  <td class=xl32>@m2月上旬</td>
  <td class=xl32>@m2月中旬</td>
  <td class=xl32>@m2月下旬</td>
  <td class=xl32>@m3月上旬</td>
  <td class=xl32>@m3月中旬</td>
  <td class=xl32>@m3月下旬</td>
 </tr>";
            string part2 = @"<tr height=50 style='mso-height-source:userset;height:25.5pt'>
  <td colspan=13 height=50 class=xl35 style='height:25.5pt'>@年度年@季度季度油管中标合同计划及完成情况</td>
 </tr>
 <tr height=19 style='height:14.25pt'>
  <td rowspan=2 height=38 class=xl25 style='border-bottom:.5pt solid black;
  height:28.5pt;border-top:none'>序号</td>
  <td rowspan=2 class=xl25 style='border-bottom:.5pt solid black;border-top:
  none'>中标单位</td>
  <td rowspan=2 class=xl25 style='border-bottom:.5pt solid black;border-top:
  none'>数量(吨)</td>
  <td rowspan=2 class=xl26 width=72 style='border-bottom:.5pt solid black;
  border-top:none;width:54pt'>单价<br>
    (元/吨)</td>
  <td colspan=9 class=xl27 style='border-right:.5pt solid black;border-left:
  none'>交货时间</td>
 </tr>
 <tr height=19 style='height:14.25pt'>
  <td height=19 class=xl32 style='height:14.25pt'>@m1月上旬</td>
  <td class=xl32>@m1月中旬</td>
  <td class=xl32>@m1月下旬</td>
  <td class=xl32>@m2月上旬</td>
  <td class=xl32>@m2月中旬</td>
  <td class=xl32>@m2月下旬</td>
  <td class=xl32>@m3月上旬</td>
  <td class=xl32>@m3月中旬</td>
  <td class=xl32>@m3月下旬</td>
 </tr>";

            string part3 = @" <![if supportMisalignedColumns]>
 <tr height=0 style='display:none'>
  <td width=72 style='width:54pt'></td>
  <td width=87 style='width:65pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
 </tr>
 <![endif]>
</table>";
            Response.Charset = "utf-8";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.ContentType = "application/ms-excel";
            Response.AddHeader("content-disposition", "attachment; filename=\"" + Server.UrlEncode("合同计划及完成情况") + ".xls\"");
            part1 = part1.Replace("@年度", 年度);
            part1 = part1.Replace("@季度", 季度);
            part1 = part1.Replace("@m1", m1.ToString());
            part1 = part1.Replace("@m2", m2.ToString());
            part1 = part1.Replace("@m3", m3.ToString());
            Response.Write(part1);
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
//            string sql = @"select 名称,数量,单价,交货数量1,交货数量2,交货数量3,交货数量4,交货数量5,交货数量6,交货数量7,交货数量8,交货数量9,
//                        dbo.当旬合同到货量('套管光管',原料供货单位.名称,@年度,@月份1,'上旬'),dbo.当旬合同到货量('套管光管',原料供货单位.名称,@年度,@月份1,'中旬'),dbo.当旬合同到货量('套管光管',原料供货单位.名称,@年度,@月份1,'下旬'),
//                        dbo.当旬合同到货量('套管光管',原料供货单位.名称,@年度,@月份2,'上旬'),dbo.当旬合同到货量('套管光管',原料供货单位.名称,@年度,@月份2,'中旬'),dbo.当旬合同到货量('套管光管',原料供货单位.名称,@年度,@月份2,'下旬'),
//                        dbo.当旬合同到货量('套管光管',原料供货单位.名称,@年度,@月份3,'上旬'),dbo.当旬合同到货量('套管光管',原料供货单位.名称,@年度,@月份3,'中旬'),dbo.当旬合同到货量('套管光管',原料供货单位.名称,@年度,@月份3,'下旬')
//                        from 采购原料合同 inner Join 原料供货单位 on 采购原料合同.供货ID=原料供货单位.ID where 年度=@年度 and 季度=@季度 and 原料ID=@原料ID";
            string sql = @"select 名称,数量,单价,交货数量1,交货数量2,交货数量3,交货数量4,交货数量5,交货数量6,交货数量7,交货数量8,交货数量9,
                        实际交货数量1,实际交货数量2,实际交货数量3,实际交货数量4,实际交货数量5,实际交货数量6,实际交货数量7,实际交货数量8,实际交货数量9
                        from 采购原料合同 inner Join 原料供货单位 on 采购原料合同.供货ID=原料供货单位.ID where 年度=@年度 and 季度=@季度 and 原料ID=@原料ID";
            sql = sql.Replace("@年度", this.Year.Text);
            sql = sql.Replace("@季度", 季度);
            sql = sql.Replace("@月份1", m1.ToString());
            sql = sql.Replace("@月份2", m2.ToString());
            sql = sql.Replace("@月份3", m3.ToString());
            sql = sql.Replace("@原料ID", "2");
            Cmd.CommandText = sql;
            DataSet ds = new DataSet();

            SqlDataAdapter sda = new SqlDataAdapter(sql, Conn);
            sda.Fill(ds);
            DataTable dt = ds.Tables[0];
            int 套管光管 = dt.Rows.Count;
            SqlDataReader Reader = Cmd.ExecuteReader();
            int i = 0;
            while (Reader.Read())
            {

                if (套管光管 != 0)
                {
                    ++i;
                    Response.Write("<tr height=19 style='height:14.25pt'><td height=19 class=xl33 style='height:14.25pt' x:num>" + i + "</td>");
                    Response.Write("<td class=xl34 style='border-top:none;border-left:none'>" + Reader.GetString(0) + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(1).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(2).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(3).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(4).ToString("0") + "　</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(5).ToString("0") + "　</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(6).ToString("0") + "　</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(7).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(8).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(9).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(10).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(11).ToString("0") + "</td></tr>");
                 

                    Response.Write(" <tr height=19 style='height:14.25pt'><td height=19 class=xl36 style='height:14.25pt;border-top:none'></td>");
                    Response.Write("<td class=xl34 style='border-top:none;border-left:none'>合计到货量</td>");
                    套管合计到货量 = Reader.GetDecimal(12) + Reader.GetDecimal(13) + Reader.GetDecimal(14) + Reader.GetDecimal(15) + Reader.GetDecimal(16) + Reader.GetDecimal(17) + Reader.GetDecimal(18) + Reader.GetDecimal(19) + Reader.GetDecimal(20);
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + 套管合计到货量.ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(12).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(13).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(14).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(15).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(16).ToString("0") + "　</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(17).ToString("0") + "　</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(18).ToString("0") + "　</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(19).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(20).ToString("0") + "</td></tr>");
                 

                    Response.Write("<tr height=19 style='height:14.25pt'><td height=19 class=xl33 style='height:14.25pt;border-top:none' x:num></td>");
                    Response.Write("<td class=xl34 style='border-top:none;border-left:none'>未按期量</td>");
                    string xun = 当前旬;
                    decimal 未按期量 = 0;
                    if (xun == "1月上旬" || xun == "4月上旬" || xun == "7月上旬" || xun == "10月上旬")
                    {
                        未按期量 = Reader.GetDecimal(12) - Reader.GetDecimal(3);
                    }
                    if (xun == "1月中旬" || xun == "4月中旬" || xun == "7月中旬" || xun == "10月中旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13)) - (Reader.GetDecimal(3) + Reader.GetDecimal(4));
                    }
                    if (xun == "1月下旬" || xun == "4月下旬" || xun == "7月下旬" || xun == "10月下旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13) + Reader.GetDecimal(14))
                            - (Reader.GetDecimal(3) + Reader.GetDecimal(4) + Reader.GetDecimal(5));
                    }
                    if (xun == "2月上旬" || xun == "5月上旬" || xun == "8月上旬" || xun == "11月上旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13) +
                            Reader.GetDecimal(14) + Reader.GetDecimal(15))
                            - (Reader.GetDecimal(3) + Reader.GetDecimal(4) + Reader.GetDecimal(5) + Reader.GetDecimal(6));
                    }
                    if (xun == "2月中旬" || xun == "5月中旬" || xun == "8月中旬" || xun == "11月中旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13) +
                            Reader.GetDecimal(14) + Reader.GetDecimal(15) + Reader.GetDecimal(16))
                            - (Reader.GetDecimal(3) + Reader.GetDecimal(4) + Reader.GetDecimal(5) +
                            Reader.GetDecimal(6) + Reader.GetDecimal(7));
                    }
                    if (xun == "2月下旬" || xun == "5月下旬" || xun == "8月下旬" || xun == "11月下旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13) +
                            Reader.GetDecimal(14) + Reader.GetDecimal(15) + Reader.GetDecimal(16) + Reader.GetDecimal(17))
                            - (Reader.GetDecimal(3) + Reader.GetDecimal(4) + Reader.GetDecimal(5) +
                            Reader.GetDecimal(6) + Reader.GetDecimal(7) + Reader.GetDecimal(8));
                    }
                    if (xun == "3月上旬" || xun == "6月上旬" || xun == "9月上旬" || xun == "12月上旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13) +
                            Reader.GetDecimal(14) + Reader.GetDecimal(15) + Reader.GetDecimal(16) + Reader.GetDecimal(17)
                            + Reader.GetDecimal(18))
                            - (Reader.GetDecimal(3) + Reader.GetDecimal(4) + Reader.GetDecimal(5) +
                            Reader.GetDecimal(6) + Reader.GetDecimal(7) + Reader.GetDecimal(8) + Reader.GetDecimal(9));
                    }
                    if (xun == "3月中旬" || xun == "6月中旬" || xun == "9月中旬" || xun == "12月中旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13) +
                            Reader.GetDecimal(14) + Reader.GetDecimal(15) + Reader.GetDecimal(16) + Reader.GetDecimal(17)
                            + Reader.GetDecimal(18) + Reader.GetDecimal(19))
                            - (Reader.GetDecimal(3) + Reader.GetDecimal(4) + Reader.GetDecimal(5) +
                            Reader.GetDecimal(6) + Reader.GetDecimal(7) + Reader.GetDecimal(8) +
                            Reader.GetDecimal(9) + Reader.GetDecimal(10));
                    }
                    if (xun == "3月下旬" || xun == "6月下旬" || xun == "9月下旬" || xun == "12月下旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13) +
                            Reader.GetDecimal(14) + Reader.GetDecimal(15) + Reader.GetDecimal(16) + Reader.GetDecimal(17)
                            + Reader.GetDecimal(18) + Reader.GetDecimal(19) + Reader.GetDecimal(20))
                            - (Reader.GetDecimal(3) + Reader.GetDecimal(4) + Reader.GetDecimal(5) +
                            Reader.GetDecimal(6) + Reader.GetDecimal(7) + Reader.GetDecimal(8) +
                            Reader.GetDecimal(9) + Reader.GetDecimal(10) + Reader.GetDecimal(11));
                    }
                    套管欠交 = 未按期量 + 套管欠交;
                    套管未完成合同量 = 套管未完成合同量 + (Reader.GetDecimal(1) - 套管合计到货量);
                    if (未按期量 > 0)
                    {
                        套管提前交货量 = 未按期量 + 套管提前交货量;
                    }
                    Response.Write("<td class=xl25 style='border-top:none;border-left:none'>" + 未按期量.ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td></tr>");            

                }
            }

            Reader.Close();

            part2 = part2.Replace("@年度", 年度);
            part2 = part2.Replace("@季度", 季度);
            part2 = part2.Replace("@m1", m1.ToString());
            part2 = part2.Replace("@m2", m2.ToString());
            part2 = part2.Replace("@m3", m3.ToString());
            Response.Write(part2);
//            string sql1 = @"select 名称,数量,单价,交货数量1,交货数量2,交货数量3,交货数量4,交货数量5,交货数量6,交货数量7,交货数量8,交货数量9,
//      dbo.当旬合同到货量('油管光管',原料供货单位.名称,@年度,@月份1,'上旬'),dbo.当旬合同到货量('油管光管','@供应单位',@年度,@月份1,'中旬'),dbo.当旬合同到货量('油管光管','@供应单位',@年度,@月份1,'下旬'),
//      dbo.当旬合同到货量('油管光管',原料供货单位.名称,@年度,@月份2,'上旬'),dbo.当旬合同到货量('油管光管','@供应单位',@年度,@月份2,'中旬'),dbo.当旬合同到货量('油管光管','@供应单位',@年度,@月份2,'下旬'),
//      dbo.当旬合同到货量('油管光管',原料供货单位.名称,@年度,@月份3,'上旬'),dbo.当旬合同到货量('油管光管','@供应单位',@年度,@月份3,'中旬'),dbo.当旬合同到货量('油管光管','@供应单位',@年度,@月份3,'下旬')
//
//      from 采购原料合同 inner Join 原料供货单位 on 采购原料合同.供货ID=原料供货单位.ID where 年度=@年度 and 季度=@季度 and 原料ID=@原料ID";
            string sql1 = @"select 名称,数量,单价,交货数量1,交货数量2,交货数量3,交货数量4,交货数量5,交货数量6,交货数量7,交货数量8,交货数量9,
      实际交货数量1,实际交货数量2,实际交货数量3,实际交货数量4,实际交货数量5,实际交货数量6,实际交货数量7,实际交货数量8,实际交货数量9
      from 采购原料合同 inner Join 原料供货单位 on 采购原料合同.供货ID=原料供货单位.ID where 年度=@年度 and 季度=@季度 and 原料ID=@原料ID";
            sql1 = sql1.Replace("@年度", this.Year.Text);
            sql1 = sql1.Replace("@季度", 季度);
            sql1 = sql1.Replace("@月份1", m1.ToString());
            sql1 = sql1.Replace("@月份2", m2.ToString());
            sql1 = sql1.Replace("@月份3", m3.ToString());
            sql1 = sql1.Replace("@原料ID", "1");
            Cmd.CommandText = sql1;
            DataSet ds1 = new DataSet();
            SqlDataAdapter sda1 = new SqlDataAdapter(sql1, Conn);
            sda1.Fill(ds1);
            dt = ds1.Tables[0];
            int 油管光管 = dt.Rows.Count;
            Reader = Cmd.ExecuteReader();

            int j = 0;
            while (Reader.Read())
            {

                if (油管光管 != 0)
                {
                    ++j;
                    Response.Write("<tr height=19 style='height:14.25pt'><td height=19 class=xl33 style='height:14.25pt' x:num>" + j + "</td>");
                    Response.Write("<td class=xl34 style='border-top:none;border-left:none'>" + Reader.GetString(0) + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(1).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(2).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(3).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(4).ToString("0") + "　</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(5).ToString("0") + "　</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(6).ToString("0") + "　</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(7).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(8).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(9).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(10).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(11).ToString("0") + "</td></tr>");

                    Response.Write(" <tr height=19 style='height:14.25pt'><td height=19 class=xl36 style='height:14.25pt;border-top:none'></td>");
                    Response.Write("<td class=xl34 style='border-top:none;border-left:none'>合计到货量</td>");
                    油管合计到货量 = Reader.GetDecimal(12) + Reader.GetDecimal(13) + Reader.GetDecimal(14) + Reader.GetDecimal(15) + Reader.GetDecimal(16) + Reader.GetDecimal(17) + Reader.GetDecimal(18) + Reader.GetDecimal(19) + Reader.GetDecimal(20);
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + 油管合计到货量.ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(12).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(13).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none' x:num>" + Reader.GetDecimal(14).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(15).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(16).ToString("0") + "　</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(17).ToString("0") + "　</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(18).ToString("0") + "　</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(19).ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + Reader.GetDecimal(20).ToString("0") + "</td></tr>");

                    Response.Write("<tr height=19 style='height:14.25pt'><td height=19 class=xl33 style='height:14.25pt;border-top:none' x:num></td>");
                    Response.Write("<td class=xl34 style='border-top:none;border-left:none'>未按期量</td>");
                    string xun = 当前旬;
                    decimal 未按期量 = 0;
                    if (xun == "1月上旬" || xun == "4月上旬" || xun == "7月上旬" || xun == "10月上旬")
                    {
                        未按期量 = Reader.GetDecimal(12) - Reader.GetDecimal(3);
                    }
                    if (xun == "1月中旬" || xun == "4月中旬" || xun == "7月中旬" || xun == "10月中旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13)) - (Reader.GetDecimal(3) + Reader.GetDecimal(4));
                    }
                    if (xun == "1月下旬" || xun == "4月下旬" || xun == "7月下旬" || xun == "10月下旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13) + Reader.GetDecimal(14))
                            - (Reader.GetDecimal(3) + Reader.GetDecimal(4) + Reader.GetDecimal(5));
                    }
                    if (xun == "2月上旬" || xun == "5月上旬" || xun == "8月上旬" || xun == "11月上旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13) +
                            Reader.GetDecimal(14) + Reader.GetDecimal(15))
                            - (Reader.GetDecimal(3) + Reader.GetDecimal(4) + Reader.GetDecimal(5) + Reader.GetDecimal(6));
                    }
                    if (xun == "2月中旬" || xun == "5月中旬" || xun == "8月中旬" || xun == "11月中旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13) +
                            Reader.GetDecimal(14) + Reader.GetDecimal(15) + Reader.GetDecimal(16))
                            - (Reader.GetDecimal(3) + Reader.GetDecimal(4) + Reader.GetDecimal(5) +
                            Reader.GetDecimal(6) + Reader.GetDecimal(7));
                    }
                    if (xun == "2月下旬" || xun == "5月下旬" || xun == "8月下旬" || xun == "11月下旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13) +
                            Reader.GetDecimal(14) + Reader.GetDecimal(15) + Reader.GetDecimal(16) + Reader.GetDecimal(17))
                            - (Reader.GetDecimal(3) + Reader.GetDecimal(4) + Reader.GetDecimal(5) +
                            Reader.GetDecimal(6) + Reader.GetDecimal(7) + Reader.GetDecimal(8));
                    }
                    if (xun == "3月上旬" || xun == "6月上旬" || xun == "9月上旬" || xun == "12月上旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13) +
                            Reader.GetDecimal(14) + Reader.GetDecimal(15) + Reader.GetDecimal(16) + Reader.GetDecimal(17)
                            + Reader.GetDecimal(18))
                            - (Reader.GetDecimal(3) + Reader.GetDecimal(4) + Reader.GetDecimal(5) +
                            Reader.GetDecimal(6) + Reader.GetDecimal(7) + Reader.GetDecimal(8) + Reader.GetDecimal(9));
                    }
                    if (xun == "3月中旬" || xun == "6月中旬" || xun == "9月中旬" || xun == "12月中旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13) +
                            Reader.GetDecimal(14) + Reader.GetDecimal(15) + Reader.GetDecimal(16) + Reader.GetDecimal(17)
                            + Reader.GetDecimal(18) + Reader.GetDecimal(19))
                            - (Reader.GetDecimal(3) + Reader.GetDecimal(4) + Reader.GetDecimal(5) +
                            Reader.GetDecimal(6) + Reader.GetDecimal(7) + Reader.GetDecimal(8) +
                            Reader.GetDecimal(9) + Reader.GetDecimal(10));
                    }
                    if (xun == "3月下旬" || xun == "6月下旬" || xun == "9月下旬" || xun == "12月下旬")
                    {
                        未按期量 = (Reader.GetDecimal(12) + Reader.GetDecimal(13) +
                            Reader.GetDecimal(14) + Reader.GetDecimal(15) + Reader.GetDecimal(16) + Reader.GetDecimal(17)
                            + Reader.GetDecimal(18) + Reader.GetDecimal(19) + Reader.GetDecimal(20))
                            - (Reader.GetDecimal(3) + Reader.GetDecimal(4) + Reader.GetDecimal(5) +
                            Reader.GetDecimal(6) + Reader.GetDecimal(7) + Reader.GetDecimal(8) +
                            Reader.GetDecimal(9) + Reader.GetDecimal(10) + Reader.GetDecimal(11));
                    }
                    油管欠交 = 未按期量 + 油管欠交;
                    油管未完成合同量 = 油管未完成合同量 + (Reader.GetDecimal(1) - 油管合计到货量);
                    if (未按期量 > 0)
                    {
                        油管提前交货量 = 未按期量 + 油管提前交货量;
                    }
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'>" + 未按期量.ToString("0") + "</td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td>");
                    Response.Write("<td class=xl32 style='border-top:none;border-left:none'></td></tr>");            


                }
            }
            Cmd.Clone();
            Reader.Close();
            Conn.Close();
            Response.Write(" <tr height=19 style='height:14.25pt'><td height=19 class=xl37 style='height:14.25pt'></td><td class=xl39></td><td colspan=11 class=xl37 style='mso-ignore:colspan'></td></tr>");
            Response.Write("<tr height=19 style='height:14.25pt'>");
            Response.Write("<td height=19 style='height:14.25pt'></td>");
            Response.Write("<td colspan=9 class=xl38>本期合同套管欠交" + (套管提前交货量 + (-(套管欠交))).ToString("0") + "吨,提前交货" + 套管提前交货量.ToString("0") + "吨,合计欠交" + (-(套管欠交)).ToString("0") + "吨,未完成合同量" + 套管未完成合同量.ToString("0") + "吨</td>");
            Response.Write("<td colspan=3 style='mso-ignore:colspan'></td></tr>"); 
          
            Response.Write("<tr height=19 style='height:14.25pt'>");
            Response.Write("<td height=19 style='height:14.25pt'></td>");
            Response.Write("<td colspan=9 class=xl38>本期合同油管欠交" + (油管提前交货量 + (-(油管欠交))).ToString("0") + "吨,提前交货" + 油管提前交货量.ToString("0") + "吨,合计欠交" + (-(油管欠交)).ToString("0") + "吨,未完成合同量" + 油管未完成合同量.ToString("0") + "吨</td>");
            Response.Write("<td colspan=2 class=xl37>" + this.RiQi.Text + "</td></tr>");
            Response.Write(part3);
            Response.End();
          
        }
    }
}
